<?
Header("Pragma: No-cache");
session_start();
set_include_path('./../../nearestCaches/library' . PATH_SEPARATOR . get_include_path());
$PEAR_PATH = 'PEAR.php';
include ('Request/Request.php');
include "functions.php";
$lang = getLang();
$versionInt = getClientIntVersion();

global $viewstate;
global $postback;
global $cookie;

//get page of selected cache
$url = "http://www.geocaching.com/seek/cache_details.aspx?guid=".$_GET['guid'];
$req = & new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
$req->addCookie('ASP.NET_SessionId', $_SESSION['cookie']);
$req->sendRequest();
$response = $req->getResponseBody();

$html = '<?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html>
                <head>
                    <title>'.$lang['inventory'].'</title>
                <body class="list"><ul>';
        $position = 0;
        $response = parseBetween('<span id="ctl00_ContentBody_lnkTravelBugs"></span>', '</table>');
        $table = array();
        $i = 0;
        while($position = strpos(' '.$response, '<tr>')) {
            $allTable = $response;
            $position = 0;
            $tr = parseBetween('<tr>', '</tr>');
            $response = $tr;
            $position = 0;
            $td = parseBetween('<td', '</td>');
            $td = substr($td, (strpos($td, '>')+1));

            $table[$i] = $td;
            $tr = substr($tr, (strpos($tr, '</td>')+5));

            $response = substr($allTable, (strpos($allTable, '<tr>')+4));
            $response = substr($response, (strpos($response, '</tr>')+5));
            $i++;
        }
        //output
        $odstraneno=array_pop($table);
        foreach($table as $inventory) {
            if(!empty($inventory)) {
                $position = 0;
                $response = $inventory;
                $inName = parseBetween('\'>', '</a>');
                $inImg = str_Replace('\'', '', trim(parseBetween('<img src=\'', 'align')));
                $inGUID = parseBetween('http://www.geocaching.com/track/details.aspx?guid=', '\'>');
                $html .= '<li><img src="'.$inImg.'" /> <a href="'.SERVICE_URL.'inventory_detail.php?show=desc&amp;guid='.$inGUID.'">'.$inName.'</a></li>'."\n";
            }
        }
        $html .= '</ul></body></html>';
        echo $html;
?>
